package com.team5.mapper;

import java.util.List;

import com.team5.entity.ChinaIndex;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ChinaIndexMapper {
    @Select("select * from \"SCOTT\".CHINA_INDEX where id=#{id}")
    ChinaIndex findById(Integer id);
    @Select("select * from \"SCOTT\".CHINA_INDEX")
    ChinaIndex[] findAll();
    @Select("select * from \"SCOTT\".CHINA_INDEX")
    List<ChinaIndex> list();

    @Delete("delete from \"SCOTT\".CHINA_INDEX where id=#{id}")
    int deleteById(Integer id);

    @Delete("delete from \"SCOTT\".CHINA_INDEX where name=#{name}")
    int deleteByName(String name);
    @Delete("delete from \"SCOTT\".CHINA_INDEX")
    int deleteAll();

    @Insert("insert into \"SCOTT\".CHINA_INDEX (id, name, price) " +
            "values (#{id}, #{name}, #{price})")
    @SelectKey(statement = "SELECT seq_china.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = int.class)
    int insert(ChinaIndex chinaIndex);

    @Update("update \"SCOTT\".CHINA_INDEX set " +
            "name=#{name}, price=#{price} where id=#{id}")
    int updateById(ChinaIndex chinaIndex);

    @Update("update \"SCOTT\".CHINA_INDEX set " +
                "price=#{chinaIndex.price} where name=#{chinaIndex.name}")
    int updatePriceByName(@Param("chinaIndex")ChinaIndex chinaIndex);


}
